<script setup>
import {
  EllipsisOutlined,
  CheckOutlined,
  ExclamationCircleOutlined,
  SyncOutlined,

} from "@ant-design/icons-vue";
import { computed, reactive, ref, createVNode, defineComponent } from "vue";
import { Modal, message } from "ant-design-vue";
import { useRoute, useRouter } from "vue-router";
const route = useRoute();
const router = useRouter();

const emit = defineEmits(["changeName:name", 'delItem:id']);
const props = defineProps({
  options: {
    type: Object,
    default: () => {
      return {
        showKes: [
          "shengcheng",
          "chuagnzuo",
          "fabu",
          "xiazai",
          "chongmingming",
          "shanchu",
        ],
      };
    },
  },
  item: {
    type: Object,
    default: () => {
      return {
        name: "",
      };
    },
  },
});

const state = reactive({
  // 开启编辑名称
  editName: false,
});

// 名称计算属性代理
const isName = computed({
  get() {
    console.log(props.item);

    return props.item.name;
  },
  set(val) {
    emit("changeName", val);
  },
});



// 定义状态颜色映射
const statusColors = {
  0: { backgroundColor: '#fff', color: '#232323' }, //准备中
  1: { backgroundColor: '#fff', color: '#faad14' }, //排队中
  2: { backgroundColor: '#fff', color: '#1677ff' }, //训练中
  3: { backgroundColor: '#fff', color: '#52c41a' }, //训练成功
  4: { backgroundColor: '#fff', color: '#ff4d4f' }, //任务失败
};


const cloneItem = ref(null);
const showInput = () => {
  state.editName = !state.editName;
  cloneItem.value = JSON.parse(JSON.stringify(props.item));
};

const deleteClick = () => {
  console.log("删除");
  Modal.confirm({
    title: "确定要删除该视频吗?",
    icon: createVNode(ExclamationCircleOutlined),
    okText: "确定",
    cancelText: "取消",
    onOk() {
      console.log("OK");
    },
  });
};

// 视频生成
const goGenerateVideo = (name, id) => {
  router.push({
    name,
    query: { id },
  });
};


// 删除某项视频
const delItem = (id) => {
  Modal.confirm({
    title: "确定要删除该视频吗?",
    icon: createVNode(ExclamationCircleOutlined),
    okText: "确定",
    cancelText: "取消",
    onOk() {
      emit('delItem', id)
    },
  });
}
</script>

<template>
  <!-- 每一项内容 -->
  <div class="content_items">
    <span data-v-459c649f="" class="schedule" :style="{
      'background-color': statusColors[props.item.status]?.backgroundColor || '#fff',
      color: statusColors[props.item.status]?.color || '#ff4d4f'
    }">
      <!-- {{ props.item.status_text + 'props.item.status_text' }} -->
      <sync-outlined :spin="true" v-if="[0, 1, 2].includes(props.item.status)" />
    ID:{{ props.item.id  }} &nbsp;
      {{ props.item.status_txt }}
    </span>
    <div class="is_top_box">
      <div class="mask_top">
        <a-popover :title="null" placement="bottomRight" :getPopupContainer="triggerNode => {
          return triggerNode.parentNode;
        }
          ">
          <template #content>
            <div style="display: flex; flex-direction: column; justify-content: center;">
              <a-button type="link" :disabled="props.item.status != 3" v-if="props.item.status == 3"
                @click="goGenerateVideo('AIdigitalHumanCreatVideo', props.item.id)">
                生成视频
              </a-button>
              <a-button danger type="link"  v-if="props.item.isDel == 1" 
                @click="delItem(props.item.id)">
                删除视频
              </a-button>
            </div>
          </template>
          <EllipsisOutlined v-if="props.item.status == 4 || props.item.status == 3" class="creat_video_btn">
          </EllipsisOutlined>
        </a-popover>
      </div>
      <template v-if="props.item.url_image">
        <img class="is_video" :src="props.item.url_image" alt="">
      </template>

      <template v-else>
        <video class="is_video" :src="props.item.video_url"></video>
      </template>


    </div>
    <a-button v-if="props.item.status == 3" class="is_btn" type="primary"
      @click="goGenerateVideo('AIdigitalHumanCreatVideo', props.item.id)">
      生成视频
    </a-button>

    <div class="is_controls">
      <div class="is_controls_left">
        <template v-if="state.editName">
          <a-input class="is_input" size="small" v-model:value="isName" placeholder="请输入名称">
            <template #suffix>
              <CheckOutlined class="ok_icon"></CheckOutlined>
            </template>
          </a-input>
        </template>
        <template v-else>
          <a-tooltip placement="top">
            <template #title>
              <span>{{ isName }}</span>
            </template>
            <span class="is_name">{{ isName }}</span>
          </a-tooltip>
        </template>

        <!-- <template v-else> -->
        <span class="is_time">{{ props.item.speaker_time }}</span>
        <!-- </template> -->
      </div>
      <!-- <div class="is_controls_right">
        <a-popover placement="right" :title="null">
          <template #content>
            <div
              style="
                display: flex;
                flex-direction: column;
                justify-content: center;
              "
            >
              <a-button
                type="link"
                v-if="props.options.showKes.includes('chuagnzuo')"
                >去创作</a-button
              >
              <a-button
                type="link"
                v-if="props.options.showKes.includes('fabu')"
                >去发布</a-button
              >
              <a-button
                type="link"
                v-if="props.options.showKes.includes('xiazai')"
                >下载</a-button
              >
              <a-button
                type="link"
                v-if="props.options.showKes.includes('chongmingming')"
                @click="showInput"
                >重命名</a-button
              >
              <a-button
                type="link"
                danger
                v-if="props.options.showKes.includes('shanchu')"
                @click="deleteClick"
                >删除</a-button
              >
            </div>
          </template>
          <EllipsisOutlined class="more_icon"></EllipsisOutlined>
        </a-popover>
      </div> -->
    </div>
  </div>
</template>

<style lang="less" scoped>
@fs_color: rgba(112, 112, 112, 1);



// 卡片样式提取到外层
.content_items,
.cart_creat {
  height: 300px;
  width: 210px;
  min-width: 210px;
  // max-width: 190px;
  background-color: #f7f7f5;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-size: 13px;
  color: @fs_color;
  border: 1px dashed #a5a5a5;
  border-radius: 10px;
  gap: 5px;
  overflow: hidden;
  transition: all 0.3s;
  cursor: pointer;
  position: relative;

  &:hover {
    border-color: var(--ss-primary-color-active);

    & .is_top_box .creat_video_btn {
      opacity: 1;
    }
  }

  .add_icon {
    font-size: 30px;
  }

  .schedule {
    position: absolute;
    right: 0px;
    top: 0px;
    z-index: 4;
    background-color: var(--ss-primary-4);
    color: #fff;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 0 0 0 8px;
  }
}

// 编辑的每一项
.content_items {
  display: flex;
  flex-direction: column;
  position: relative;

  &:hover {
    & .is_btn {
      opacity: 1;
    }
  }

  .is_btn {
    position: absolute;
    width: 120px;
    top: 50%;
    left: 50%;
    transform: translate(-50%);
    opacity: 0;
  }

  .is_top_box {
    flex: 1;
    width: 100%;
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #000000;


    .mask_top {
      position: absolute;
      left: 0;
      top: 0;
      background-color: #5353538a;
      z-index: 3;
      width: 100%;
      height: 30px;

      :deep(.ss-popover-inner-content) {
        padding: 5px;

      }

      .creat_video_btn {
        color: #fff;
        position: absolute;
        top: 1px;
        left: 10px;
        z-index: 9;
        opacity: 1;
        transition: all 0.3s;
        font-size: 30px;
        font-weight: 900;

        &:hover {
          color: var(--ss-primary-color-hover);
        }
      }
    }


    .is_video {
      height: 100%;
      width: auto;
      // background-color: #dadada;
    }
  }

  .is_controls {
    position: absolute;
    padding: 5px 10px;
    width: 100%;
    bottom: 0;
    left: 0;
    display: flex;
    justify-content: space-between;
    background-color: #5353538a;
    color: #fff;

    .is_controls_left {
      width: 70%;
      font-size: 14px;
      width: 100%;
      display: flex;
      flex-direction: column;
      color: @fs_color;

      .is_input {
        width: 160px;
      }

      .is_name {
        color: #fff;
        line-height: 24px;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
        width: auto;
      }

      .is_time {
        color: #fff;
      }
      .ok_icon {
        transition: all 0.3s;
        color: #5e5e5e;

        &:hover {
          color: var(--ss-primary-color-hover);
        }
      }
    }

    .is_controls_right {
      cursor: pointer;

      .more_icon {
        font-size: 20px;
        font-weight: 900;
      }
    }
  }
}
</style>
